#include "checkbox.h"
#include "ui_checkbox.h"
int CheckBox::check = -1;
CheckBox::CheckBox(QWidget *parent) :
    QWidget(parent, Qt::FramelessWindowHint | Qt::Window | Qt::WindowMinimizeButtonHint)
       , ui(new Ui::CheckBox)
{
    check = -1;
    setWindowFlag(Qt::FramelessWindowHint, true);
    setWindowFlag(Qt::Window, true);
    setWindowFlag(Qt::WindowMinimizeButtonHint, true);
    setAttribute(Qt::WA_TranslucentBackground);
    ui->setupUi(this);
}

CheckBox::~CheckBox()
{
    //check = -1;
    delete ui;
}
void CheckBox::mousePressEvent(QMouseEvent*event)
{
    if(event->button()==Qt::LeftButton) //如果鼠标左键按下
    {
        isPressed=true;
        curPos = event->pos();    //记录当前的点击坐标
    }
}

void CheckBox::mouseMoveEvent(QMouseEvent*event)
{
    if(isPressed) //如果鼠标左键按下
    {
        this->move(event->pos()-curPos+this->pos());
        //窗口移动
    }
}

//鼠标释放
void CheckBox::mouseReleaseEvent(QMouseEvent*event)
{
    isPressed=false;
}

void CheckBox::paintEvent(QPaintEvent *event)
{
    QStyleOption opt;
    opt.init(this);
    QPainter painter(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
}

void CheckBox::closeEvent(QCloseEvent *event)
{
    qDebug() << check;
}


void CheckBox::on_btnOk_clicked()
{
    check = 1;
    close();
}

void CheckBox::on_btnCan_clicked()
{
    check = 2;
    close();
}
